package com.sec.android.app.myfiles.launch;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;

import com.sec.android.app.myfiles.facade.MyFilesFacade;
import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.log.Log;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

public class HandleCreateDocumentImp extends AbsHandleLaunchImp {
    @Override
    public boolean isMyJob(Intent intent) {
        final String action = intent.getAction();
        return AppConstants.Action.ACTION_CREATE_DOCUMENT.equals(action);
    }

    @Override
    public boolean _handleStart(int processId, Activity activity, Intent intent) {
        boolean ret = false;
        if (intent != null) {
            String mimeType = intent.getType();
            String title = intent.getStringExtra(Intent.EXTRA_TITLE);
            if (TextUtils.isEmpty(mimeType)) {
                Log.e(this, "_handleStart - mime type is null");
            } else if (TextUtils.isEmpty(title)) {
                Log.e(this, "_handleStart - title is null");
            } else {
                FileRecord homePath = FileRecord.createFileRecord(FileRecord.StorageType.Local, AppConstants.StoragePath.INTERNAL_ROOT);
                MyFilesFacade.createDocument(processId, homePath, NavigationInfo.NavigationMode.Select_create_doc_destination, mimeType, title);
                ret = true;
            }
        }
        return ret;
    }
}
